// Copyright 2019 The rhyme_lph Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// N [author] rhyme_lph
// w [email]  rhymelph@gmail.com
// S [github] https://github.com/rhymelph

import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/l10n.dart';
import 'package:finance_app/src/provider/setting/preference/number_format_provider.dart';
import 'package:finance_app/src/router_gen/router_meta.dart';
import 'package:finance_app/src/utils/form_utils.dart';
import 'package:finance_app/src/utils/language_utils.dart';
import 'package:finance_app/src/widgets/common_app_bar.dart';
import 'package:finance_app/src/widgets/form/value_select_form.dart';
import 'package:flutter/material.dart';

@RouterMeta(paramName: "numberFormatPage")
class NumberFormatPage extends StatefulWidget {
  @override
  _NumberFormatPageState createState() => _NumberFormatPageState();
}

class _NumberFormatPageState extends State<NumberFormatPage>
    with PagePresenter<NumberFormatPage, NumberFormatProvider> {
  @override
  PreferredSizeWidget get appBar =>
      getDefaultAppBar(title: S.current.number_format);

  @override
  Widget get buildWidget => ColoredBox(
        color: Colors.white,
        child: listBuilder<Map<String, String>>(
          selector: (_, __) => Map.from(__.formatMap),
          builder:
              (BuildContext context, Map<String, String> value, Widget child) =>
                  ListView.builder(
            itemBuilder: (context, index) {
              final e = value.entries.toList()[index];
              return ValueSelectForm(
                title:
                    LanguageUtils.translateFilter(FormUtils.keyToName(e.key)),
                value: e.value,
                onTap: () => provider.onChange(e),
              );
            },
            itemCount: value.entries.length,
          ),
        ),
      );
}
